package org.example.myleet.rosalind.utils;

public class DnaReverseComplementor {
    public static String reverseComplete(String dna) {
        char[] dnaCharArr = dna.toCharArray();
        int l = 0, r = dnaCharArr.length - 1;
        char t;
        while (l < r) {
            t = dnaCharArr[l];
            dnaCharArr[l] = dnaCharArr[r];
            dnaCharArr[r] = t;
            --r;
            ++l;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < dnaCharArr.length; ++i) {
            if (dnaCharArr[i] == 'A') {
                sb.append('T');
            } else if (dnaCharArr[i] == 'C') {
                sb.append('G');
            } else if (dnaCharArr[i] == 'G') {
                sb.append('C');
            } else if (dnaCharArr[i] == 'T') {
                sb.append('A');
            }
        }
        return sb.toString();
    }
}
